/**
 * 时间工厂
 */
class DateFactory {
  constructor() {
    this._date = new Date();
    this._year = this._date.getFullYear();
    this._month = this._date.getMonth() + 1;
    this._day = this._date.getDate();
    this._hours = this._date.getHours();
    this._minutes = this._date.getMinutes();
    this._dayTag = this._date.getDay();
  }

  /**
   * 初始化
   */
  init() {
    this._todayTimeArr = [];
    this._defaultTimeArr = [];
    this._timeArr = [];
    this._weekArr = [];
    this._hourArr = [];

    this.createTodayTimeArr(this._todayTimeArr, this._hours, this._minutes);
    this.createDefaultTimeArr(this._defaultTimeArr);

    let i, tempDayTag = this._dayTag, _this = this;
    for (i = 0; i < 14; i++) {
      if (i > 0) {
        ++tempDayTag;
      }
      if (tempDayTag > 13) {
        tempDayTag = 0;
      }
      this._weekArr.push({
        id: i,
        name: this.switchWeek(tempDayTag)
      });
      // this._hourArr.push({
      //   id: i,
      //   hourArr: i == 0 ? this._todayTimeArr : this._defaultTimeArr
      // })
    }
    // this._timeArr[1] = this._hourArr[0];
  }

  /**
   * 根据时间创建当天数组
   */
  createTodayTimeArr(todayTimeArr, currHours, minutes) {
    if (todayTimeArr) {
      let i;
      for (i = currHours; i < 24; i++) {
        if (i == currHours) {
          if (minutes < 30) {
            todayTimeArr.push({
              name: i + ":30"
            });
          }
        } else {
          todayTimeArr.push({
            name: i + ":00"
          });
          todayTimeArr.push({
            name: i + ":30"
          });
        }
      }
    }
  }


  /**
   * 其他时间数组生产
   */
  createDefaultTimeArr(defaultTimeArr) {
    if (defaultTimeArr) {
      let i;
      for (i = 0; i < 24; i++) {
        defaultTimeArr.push({
          name: i + ":00"
        });
        defaultTimeArr.push({
          name: i + ":30"
        });
      }
    }
  }

  /**
   * 选择日期
   * @param dayTag 当天时间标记戳
   * @return int 不存在返回-1，否则返回其对应的中文名称
   */
  switchWeek(dayTag) {
    let currentDayTag = dayTag > 6 ? dayTag - 7 : dayTag;
    switch (currentDayTag) {
      case 0:
        return "星期天"
        break;
      case 1:
        return "星期一"
        break;
      case 2:
        return "星期二"
        break;
      case 3:
        return "星期三"
        break;
      case 4:
        return "星期四"
        break;
      case 5:
        return "星期五"
        break;
      case 6:
        return "星期六"
        break;
    }
    return -1;
  }
}


const dateFactory = new DateFactory()
dateFactory.init();

// 录音管理器
const recorderManager = wx.getRecorderManager();
// 播放器
const innerAudioContext = wx.createInnerAudioContext()


var api = require("../../../../api.js"),
  QQMapWX = require("../../../../qqmap-wx.js"),
  app = getApp();
Page({
  data: {
    timeArr: dateFactory._timeArr,
    hourArr: dateFactory._hourArr,
    cid: '',
    rewardArr: [
      {
        price: 0,
        text: '0元'
      },
      {
        price: 1,
        text: '1元'
      },
      {
        price: 2,
        text: '2元'
      },
      {
        price: 3,
        text: '3元'
      },
      {
        price: 4,
        text: '4元'
      },
      {
        price: 5,
        text: '6元'
      },
      {
        price: 10,
        text: '10元'
      },
      {
        price: 15,
        text: '15元'
      },
      {
        price: 20,
        text: '20元'
      }
    ],
    couponArr: [
      {
        price: 0,
        text: ''
      },
    ],
    stepper: {
      stepper: 0
    },
    time: '', // 时间字符串
    vipprice:'',
    price: 0, // 跑腿费
    reward: 0,  // 小费
    coupon: 0,  // 优惠券红包
    lastPrice: 0, // 最终价格
    weight_price:'',
    full_money: '',
    integral:'',
    yinpin: '',
    detail_info: '',
    addressId: '',  // 数据库地址id
    wareText: '', // 商品名称字符串
    didianprice: 0,
    timeprice: 0,
    inputAddressText: '', // 输入的收货地址
    isReadProtocol: true,  // 是否阅读协议
    weighprice:0,
    isBargaining: false,  // 是否议价
    isOpenPreference: false, // 是否开启会员优惠
    isOpenIntegralDeduction: false,  // 是否开启积分抵扣
    show: false,
    prices:0,
    cancelWithMask: true,
    pictrueTempPath: "", // 临时途径
    weight: 0, // 重量
    soundRecording: {
      tempPath: "",
      duration: "",
      isPlay: false
    }, // 临时录音
    actions: [{
      name: '微信支付',
      subname: '使用微信官方支付方式',
      className: 'action-class',
      loading: false
    }, {
      name: '余额支付',
      subname: '使用平台账户余额支付',
      className: 'action-class',
      loading: false
    }],
    cancelText: '取消'
  },

  couponurl: function () {
    var that = this;
    app.request({
      url: api.Coupon.coupon,
      data: {
        uid: wx.getStorageSync('uid')
      },
      success: function (e) {
        console.log(e);
        that.setData({
          couponArr: e.data
        })
      }
    })
  },
  xphoto: function () {
    var that = this;
    var xphoto = that.data.xphoto;
    wx.chooseImage({
      count: 1, // 默认9
      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
      success: function (res) {
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
        var tempFilePaths = res.tempFilePaths
        wx.saveFile({
          tempFilePath: tempFilePaths[0],
          success: function (res) {
            var savedFilePath = res.savedFilePath;
            wx.uploadFile({
              url: api.default.uploadfile,
              filePath: savedFilePath,
              header: {
                'content-type': 'application/x-www-form-urlencoded'
              },
              name: 'image',
              success: function (res) {
                var ress = JSON.parse(res.data)
                console.log("图片:", ress);
                // var src = 'https://www.135k.com/addons/sd_liferuning/tp/public/uploads/xiaochengxu/201806/'
                if (ress.code == 1) {
                  var pictrueTempPath = ''
                  that.setData({
                    pictrueTempPath: ress.src,
                  })
                } else {
                  wx.showModal({
                    title: '提示',
                    content: '图片上传失败',
                    showCancel: false,
                  })
                }
              },
              fail: function (res) {
                console.log("res fail", res);
              },
            })
          }
        })
      }
    })
  },
  xphotos: function (e) {
    console.log('eee', e)
    var src = e.currentTarget.id
    wx.navigateTo({
      url: '/sd_liferuning/pages/constmer/choose-pic/index?src=' + src
    })
  },
  onLoad: function (option) {
    let _this = this;
    app.request({
      method: 'POST',
      url: api.default.orderGetPageConfig,
      data: {
        bid: wx.getStorageSync('bid')
      },
      success: function (data) {
        let status = data.status;
        let pageConfig = JSON.parse(data.diy);
        if (status) {
          // 设置标题
          wx.setNavigationBarTitle({
            title: pageConfig.titleConfig.pageTitle
          })
          // 设置颜色
          wx.setNavigationBarColor({
            frontColor: pageConfig.titleConfig.fontColor.toLocaleLowerCase(),
            backgroundColor: pageConfig.titleConfig.navigationBgColor,
            animation: {
              duration: 400,
              timingFunc: 'easeIn'
            }
          })
          console.log('-----', pageConfig)
          // 设置数据
          _this.setData({
            pageConfig: pageConfig
          });
        }
      }
    });

    var that = this;
    that.setData({
      icons: wx.getStorageSync('site') + '/addons/sd_liferuning/tp/public/uploads/background',
    })
    if (wx.getStorageSync('huiyuan') == "非会员用户") {
      that.setData({
        huiyuan: 1
      })
    }
    if (option.cid){
      that.setData({
        cid: option.cid,
      });
    }
    if (option.type_id){
      that.setData({
        typeid: option.type_id,
      });
      that.setData({
        type_status: option.type,
      });
    }
    if (that.data.typeid) {
      var typeid = that.data.typeid;
      var type_status = that.data.type_status;
      that.setData({
        typeid: typeid
      });
      app.request({
        url: api.default.TuiSongList,
        data: {
          id: typeid,
          type_status: type_status
        },
        success: function (res) {
          console.log('+++++++', res)
          that.setData({
            wareText: res.goods_name,
            detail_info: res.adress,
            username: res.name,
            phone: res.mobile,
            inputAddressText: res.address,
            old_order_no: res.order_no
          });
        }
      })
    }
    // if (wx.getStorageSync('phone') == '') {
    //   wx.redirectTo({
    //     url: '/sd_liferuning/pages/login/login',
    //   })
    // }
    if (option.addressId) {
      that.setData({
        time: option.time,
        price: option.price,
        reward: option.reward,
        coupon: option.coupon,
        lastPrice: option.lastPrice,
        addressId: option.addressId,
        inputAddressText: option.inputAddressText,
        wareText: option.wareText,
        cid: option.cid,
      });
    } else {
      that.setData({
        wareText: option.wareText ? option.wareText:'',
      });
    }
    /**
    * 时间选择
    */
    let timeArr = [];
    app.request({
      url: api.default.timelist,
      data: {
        time: 0
      },
      success: function (res) {
        timeArr[0] = dateFactory._weekArr;
        timeArr[1] = res.data;
        _this.setData({
          timeArr: timeArr
        })
      }
    })

    // 标签设置
    if (option.tags) {
      let tags = option.tags.split(',');
      _this.setData({
        tags: tags
      });
    }
  },
  onShow: function () {
    /**默认地址 */
    var that = this
    that.couponurl();
    /** 默认地址 */
    var typeid = that.data.typeid;
    if (!typeid){
      app.request({
        url: api.default.mrAddress,
        data: {
          bid: wx.getStorageSync('bid'),
          uid: wx.getStorageSync('uid')
        },
        success: function (res) {
          console.log('地址2：',res)
          if (res.data.adress == '') {
            wx.navigateTo({
              url: '/sd_liferuning/pages/constmer/address-list/index',
            })
          } else {
            that.setData({
              detail_info: res.data.adress ? res.data.adress:''
            })
          }
        }
      })
      app.request({
        url: api.default.mrAddress,
        data: {
          bid: wx.getStorageSync('bid'),
          uid: wx.getStorageSync('uid')
        },
        success: function (res) {
          console.log('地址', res);
          if (res.data == '') {
            wx.navigateTo({
              url: '/sd_liferuning/pages/constmer/address-list/index',
            })
          } else {
            that.setData({
              detail_info: res.data.adress,
              username: res.data.name,
              phone: res.data.phone
            })
          }
        }
      })
    }
  },
  /**
   * 选择位置
   */
  GetAddress: function () {
    var that = this;
    console.log('----------', that.data.detail_info)
    wx.chooseLocation({
      success: function (res) {
        that.setData({
          hasLocation: true,
          location: {
            longitude: res.longitude,   //经度
            latitude: res.latitude     //纬度
          },
          detail_infos: res.address,   //详细地址
          wd: res.latitude,
          jd: res.longitude
        })
      },
      complete(data) {
        if (that.data.detail_info != '' && that.data.wd != undefined && that.data.jd != undefined && that.data.detail_infos != '' && that.data.wd != '' && that.data.jd != '') {
          var wd = that.data.wd
          var jd = that.data.jd
          // console.log(that.data.jd);
          /**解析地址*/
          var demo = new QQMapWX({
            key: 'EKJBZ-72L3P-FHXDL-VSLEP-JEAGJ-JTFSD' // 必填
          });
          // var that = this
          demo.geocoder({
            address: that.data.detail_info,
            success: function (res) {
              // console.log('我的地址',res.result.location);
              // console.log('目的地', wd);
              /** 两个地址不为空请求金额 */
              app.request({
                url: api.default.addprice,
                metho: 'post',
                data: {
                  myaddsjd: res.result.location['lng'],
                  myaddswd: res.result.location['lat'],
                  mudaddswd: wd,
                  mudaddsjd: jd,
                  bid: wx.getStorageSync('bid')
                },
                success: function (res) {
                  var scq = that.data.didianprice
                  console.log(scq);
                  console.log('金额', res)
                  that.setData({
                    didianprice: res.data.price,
                    price: that.data.price - scq + res.data.price,
                    proxy_id: res.data.proxy_id ? res.data.proxy_id : 0,
                    region_id: res.data.region_id ? res.data.region_id : 0
                  })
                  if (res.data.region_id) {
                    wx.request({
                      url: api.default.WeightPrice,
                      data: {
                        bid: wx.getStorageSync('bid'),
                        weight: that.data.weight,
                        region_id: res.data.region_id
                      },
                      method: 'get',
                      success: function (res) {
                      that.setData({
                         weight_price: res.data.data
                      })
                 that.countPrice();
                      }
                    })
                  }
                  console.log(that.data.price,'-------------price')
                  that.countPrice();
                }

              })
            },
          });
        }
      }
    })
  },
  /**
   * 价格更改
   */
  priceSliderChange: function (e) {
    let _this = this;
    let _val = e.detail.value;
    _this.setData({
      prices:_val,
      lastPrice: _val + _this.data.price,
    });
    _this.countPrice();
  },
  pickerSelector: function (e) {
    var that = this;
    var pickerType = e.currentTarget.dataset.type;
    var val = e.detail.value;
    if (pickerType == 'time') {
      that.setData({
        time: {
          week: that.data.timeArr[0][val[0]],
          hour: that.data.timeArr[1][val[1]]
        }
      });
      /*** 时间金额*/
      var that = this
      app.request({
        url: api.default.time_price,
        data: {
          wid: that.data.timeArr[0][val[0]]['name'],
          hid: that.data.timeArr[1][val[1]]['name']
        },
        success: function (data) {
          var timeprice = that.data.timeprice
          console.log(timeprice)
          that.setData({   //显示配送时间费用
            timeprice: data.data,
          })
          that.countPrice();
        }
      })
    }
    if (pickerType == 'reward') {
      that.setData({
        reward: that.data.rewardArr[val].price
      });
    }
    if (pickerType == 'coupon') {
      that.setData({
        coupon: that.data.couponArr[val].price,
        full_money: that.data.couponArr[val].full_money,
        useid: that.data.couponArr[val].id
      });
      if (that.data.lastPrice < that.data.full_money) {
        wx.showToast({
          title: '未达到使用要求',
        })
      }
    }
    that.countPrice();
  },
  bindColumnChange: function (e) {
    var _this = this;
    var timeArr = _this.data.timeArr;
    var column = e.detail.column;
    var columnVal = e.detail.value;
    /**
    * 时间选择
    */
    if (column == 0) {
      app.request({
        url: api.default.timelist,
        data: {
          time: columnVal
        },
        success: function (res) {
          timeArr[1] = res.data;
          _this.setData({
            timeArr: timeArr
          })
        }
      })
    }
  },
  countPrice: function () {
    var that = this;
    var money = Number(that.data.prices)+ Number(that.data.stepper.stepper) + Number(that.data.reward) + Number(that.data.weight_price) - Number(that.data.integral);
    if (money < that.data.full_money) {
      money = money
      that.setData({
        coupon: 0
      })
    } else {
      money = Number(that.data.prices) + Number(that.data.stepper.stepper) + Number(that.data.reward) - Number(that.data.coupon) + Number(that.data.weight_price) - Number(that.data.integral);
    }
    if (money < 0.01) {
      money = 0.00
    }else{
      money=money
    }
    that.setData({
      lastPrice: money.toFixed(2)
    });
  },
  changeInputData: function (e) {
    // console.log('地址',11)
    // return false;
    var that = this;
    var inputName = e.currentTarget.dataset.name;
    var inputVlaue = e.detail.value;
    if (inputName == "wareText") {
      that.setData({
        wareText: inputVlaue
      });
    }
    if (inputName == "inputAddressText") {
      that.setData({
        inputAddressText: inputVlaue
      });
    }
  },
  weight: function (e) {
    console.log(e.detail.value)
    var that = this
    app.request({
      url: api.default.WeightPrice,
      data: {
        bid: wx.getStorageSync('bid'),
        weight: e.detail.value,
      },
      success: function (res) {
        //console.log('运费金额', res)
        if (res.data != '') {
          that.setData({
            weighprice: res.data,
            price: that.data.price + res.data - weighprice
          })
          that.countPrice();
        }
      }
    })

  },
  /**提交订单*/
  formSubmit: function (e) {
    console.log(e);
    var _this = this;
    var xphoto = _this.data.pictrueTempPath
    var yinpin = _this.data.yinpin
    if (e.detail.value.goodsname != '' || xphoto != '' || yinpin != '') {
      if (e.detail.value.mudadds && e.detail.value.mytimes != 'NaN' && _this.data.isReadProtocol === true) {
        if (e.detail.value.mytimes != '' && e.detail.value.mytimes != "-"){
          console.log(xphoto)
          console.log(yinpin)
          e.detail.value.xphoto = xphoto,
            e.detail.value.yinpin = yinpin,
            console.log('e.detail.value', e.detail.value)
          _this.setData({
            formData: e.detail.value,
            formId: e.detail.formId
          });
          _this.openActionsheet();
        }else{
          wx.showToast({
            title: '请选择服务预约时间',
          })
        }
       
      } else {
        wx.showToast({
          title: '信息不完善，无法下单。',
        })
      }
    } else {
      wx.showToast({
        title: '信息不完善，无法下单。',
      })
    }
  },
  /**
   * 添加商品
   */
  addWareItem: function (e) {
    let _this = this;
    let tag = e.currentTarget.dataset.tag;
    let wareText = _this.data.wareText;
    let text = wareText.trim() == '' ? tag : wareText + ", " + tag;
    _this.setData({
      wareText: text
    });
  },
  /**
   * 是否阅读协议
   */
  isRead: function (e) {
    let isReadProtocol = this.data.isReadProtocol;
    this.setData({
      isReadProtocol: !isReadProtocol
    });
  },

  // 开启选择器
  openActionsheet() {
    this.setData({
      'show': true
    });
  },
  // 关闭选择器
  closeActionSheet() {
    this.setData({
      'show': false
    });
  },
  // 根据选择进行调用事件
  clickAction({ detail }) {
    const { index } = detail;

    this.setData({
      [`actions[${index}].loading`]: true,
      actionType: index
    });

    switch (index) {
      case 0: // 0 微信支付
        this.wechatPay();
        break;
      case 1: // 1 余额支付
        this.balancePay();
        break;
    }

    setTimeout(() => {
      this.setData({
        [`show`]: false,
        [`actions[${index}].loading`]: false
      });
    }, 100);
  },
  /**
   * 微信支付
   */
  wechatPay: function () {
    let _this = this;
    let _formData = _this.data.formData;  // 表单数据
    let type_status = _this.data.type_status;
    if (type_status){
      var order_type = type_status;
    }else{
      var order_type=0
    }

    app.request({
      url: api.default.insertorder,
      data: {
        goodsname: _formData.goodsname,
        mudadds: _formData.mudadds+_formData.mudaddsinfos,
        myadds: _formData.myadds,
        times: _formData.mytimes,
        price: _formData.price,
        order_type: order_type,
        imgurl: '',
        old_order_no: _formData.old_order_no,
        xphoto: _formData.xphoto,
        yinpin: _formData.yinpin,
        uid: wx.getStorageSync('uid'),
        redbao: _formData.redbao,
        tip: _formData.tip,
        bid: wx.getStorageSync('bid'),
        'type': '代办',
        ins: 0,
        distype: 0,
        message: _formData.message,
        username: _this.data.username,
        audiotime: this.data.soundRecording.duration,
        phone: _this.data.phone,
        proxy_id: _this.data.proxy_id ? _this.data.proxy_id : 0
      },
      success: function (res) {

        if (res.data) {
          /**获取支付参数 */
          var order_no = res.data;

          app.request({
            url: api.default.orderpay,
            data: {
              order_no: res.data,
              title: '超人跑腿支付',
              uid: wx.getStorageSync('uid')
            },
            success: function (data) {
              console.log('支付参数', data.data.weixin)
              wx.requestPayment(
                {
                  'timeStamp': data.data.weixin.timeStamp,
                  'nonceStr': data.data.weixin.nonceStr,
                  'package': data.data.weixin.package,
                  'signType': 'MD5',
                  'paySign': data.data.weixin.paySign,
                  'success': function (res) {
                    if (_this.data.useid) {
                      app.request({
                        url: api.Coupon.status,
                        data: {
                          useid: _this.data.useid
                        },
                        success: function (e) {
                          console.log(e);
                        }
                      })
                    }

                    app.request({
                      url: api.user.mess,
                      data: {
                        bid: wx.getStorageSync('bid'),
                        openid: wx.getStorageSync('openid'),
                        order_no: order_no,
                        type: 'apply'
                      },
                      success: function (ddd) {
                        console.log(ddd);
                        wx.redirectTo({
                          url: '/sd_liferuning/pages/constmer/order-list/index',
                        })
                      }
                    })

                  },
                  'complete': function (res) {

                  }
                })
            }
          })
        }
      }
    })

  },
  /**
   * 余额支付
   */
  balancePay: function () {
    wx.showLoading({
      title: '请稍后',
    })
    let _this = this;
    let _formData = _this.data.formData;  // 表单数据
    let _formId = _this.data.formId;
    let type_status = _this.data.type_status;
    if (type_status) {
      var order_type = type_status;
    } else {
      var order_type = 0
    }
    app.request({
      url: api.default.insertorder,
      data: {
        distype: _formData.distype,
        goodsname: _formData.goodsname,
        mudadds: _formData.mudadds + _formData.mudaddsinfos,
        myadds: _formData.myadds,
        times: _formData.mytimes,
        price: _formData.price,
        xphoto: _formData.xphoto,
        yinpin: _formData.yinpin,
        order_type: order_type,
        uid: wx.getStorageSync('uid'),
        imgurl: '',
        redbao: _formData.redbao,
        tip: _formData.tip,
        bid: wx.getStorageSync('bid'),
        audiotime: this.data.soundRecording.duration,
        ins: _formData.ins,
        message: _formData.message,
        'type': '代办',
        username: _this.data.username,
        phone: _this.data.phone,
        order_type: order_type,
        old_order_no: _formData.old_order_no,
        proxy_id: _this.data.proxy_id ? _this.data.proxy_id : 0
      },
      success: function (e) {
        if (e.code == 1) {
          app.request({
            url: api.order.pricePay,
            method: 'post',
            data: {
              uid: wx.getStorageSync('uid'),
              order_no: e.data,
              openid: wx.getStorageSync('openid'),
              formId: _formId,
            },
            success: function (e) {
            wx.hideLoading()
              if (e.code == 1) {
                if (_this.data.useid) {
                  app.request({
                    url: api.Coupon.status,
                    data: {
                      useid: _this.data.useid
                    },
                    success: function (e) {
                      console.log(e);
                    }
                  })
                }
                wx.showToast({
                  title: e.msg,
                  duration: 1000,
                  success: function () {
                    setTimeout(function () {
                      wx.redirectTo({
                        url: '/sd_liferuning/pages/constmer/order-list/index',
                      })
                    }, 1000)
                  }
                })
              } else {
                wx.showToast({
                  title: e.msg,
                })
              }
            }
          })
        }
      }
    })

    console.log("余额支付");
  },
  /**
   * 录音开始
   */
  soundRecordingStart: function () {
    const options = {
      duration: 60000,
      sampleRate: 44100,
      numberOfChannels: 1,
      encodeBitRate: 192000,
      format: 'mp3',
      frameSize: 50
    }
    recorderManager.start(options);
  },
  /**
   * 录音完成
   */
  soundRecordingEnd: function () {
    let _this = this;
    recorderManager.stop();
    recorderManager.onStop(function (res) {
      let _tempPath = res.tempFilePath;
      let _duration = Math.ceil(res.duration / 1000);
      innerAudioContext.src = _tempPath;
      _this.setData({
        soundRecording: {
          tempPath: _tempPath,
          duration: _duration,
          isPlay: false
        }
      });
      var tempPath = _this.data.soundRecording.tempPath
      if (tempPath) {
        console.log('tempPath', tempPath)
        wx.uploadFile({
          url: api.order.uploadimg, //仅为示例，非真实的接口地址
          filePath: tempPath,
          name: 'file',
          success: function (res) {
            console.log('resres', res)
            var yinpin = res.data
            _this.setData({
              yinpin: yinpin
            })
          }
        })
      }
    });
  },
  /**
   * 录音播放
   */
  soundRecordingPlay: function () {
    let _this = this;
    let _paused = innerAudioContext.paused;
    let _soundRecording = _this.data.soundRecording;
    if (_paused) {
      innerAudioContext.play();
      _soundRecording.isPlay = true;
      setTimeout(function () {
        let _soundRecording = _this.data.soundRecording;
        _soundRecording.isPlay = false;
        _this.setData({
          soundRecording: _soundRecording
        });
      }, _soundRecording.duration * 1000)
    } else {
      innerAudioContext.stop();
      _soundRecording.isPlay = false;
    }
    _this.setData({
      soundRecording: _soundRecording
    });
  },
  /**
   * 删除录音
   */
  soundRecordingRemove: function () {
    let _this = this;
    innerAudioContext.stop();
    _this.setData({
      soundRecording: {
        tempPath: "",
        duration: "",
        isPlay: false
      }
    });
  },
  /**
   * 获取照片
   */
  takePictrue: function () {
    let _this = this;
    wx.chooseImage({
      count: 1, // 默认9
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success: function (res) {
        // 图片临时路径
        let tempFilePaths = res.tempFilePaths;
        _this.setData({
          pictrueTempPath: tempFilePaths[0]
        });
      }
    })
  },
  /**
   * 小费
   */
  handleStepperChange: function ({
    detail: stepper,
    target: {
      dataset: {
        componentId
      }
    }
  }) {
    this.setData({
      [`${componentId}.stepper`]: stepper
    });
    this.countPrice();
  },
  /**
   * 是否议价
   */
  isBargaining: function (e) {
    let isBargaining = this.data.isBargaining;
    this.setData({
      isBargaining: !isBargaining
    });
  },
  isOpenPreference: function () {
    var that=this;
    let isOpenPreference = this.data.isOpenPreference;

      if (isOpenPreference == false) {
        wx.request({
          url: api.member.rebate,
          data: {
            uid:wx.getStorageSync('uid'),
            bid: wx.getStorageSync('bid')
          },
          method: 'get',
          success: function (res) {
            that.setData({
              vipprice: res.data.data.zhekou
            })
          }
        })
      } else {
        that.setData({
          vipprice:0
        })
      }   
    this.setData({
      isOpenPreference: !isOpenPreference
    });
  },
  /**
   * 积分抵扣
   */
  isOpenIntegralDeduction: function () {
    var that = this;
    let isOpenIntegralDeduction = this.data.isOpenIntegralDeduction;
    if (isOpenIntegralDeduction == false) {
      wx.request({
        url: api.member.integral,
        data: {
          uid: wx.getStorageSync('uid'),
          bid: wx.getStorageSync('bid')
        },
        method: 'post',
        success: function (res) {
          that.setData({
            integral: res.data.data.integral
          })
        }
      })
    } else {
      that.setData({
        integral: 0
      })
    }
    this.setData({
      isOpenIntegralDeduction: !isOpenIntegralDeduction
    });
  }
})